package com.xul.yygh.hosp.controller.api;

import com.xul.yygh.common.result.Result;
import com.xul.yygh.hosp.service.DepartmentService;
import com.xul.yygh.hosp.service.HospitalService;
import com.xul.yygh.hosp.service.HospitalSetService;
import com.xul.yygh.hosp.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import model.com.xul.yygh.model.hosp.Hospital;
import model.com.xul.yygh.model.hosp.Schedule;
import model.com.xul.yygh.vo.hosp.DepartmentVo;
import model.com.xul.yygh.vo.hosp.HospitalQueryVo;
import model.com.xul.yygh.vo.hosp.ScheduleOrderVo;
import model.com.xul.yygh.vo.hosp.ScheduleQueryVo;
import model.com.xul.yygh.vo.order.OrderQueryVo;
import model.com.xul.yygh.vo.order.SignInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author xul
 * @create 2021-07-13 22:44
 */
@Api(tags = "用户段医院接口")
@RestController
@RequestMapping("api/hosp/hospital")
public class HospApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;

    /**
     * 查询医院列表
     *
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation("查询医院列表")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitals = hospitalService.findPageHospital(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    /**
     * 根据医院名称经行模糊查询
     *
     * @param hosname
     * @return
     */
    @ApiOperation("根据医院名称经行模糊查询")
    @GetMapping("findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname) {
        List<Hospital> hospitalList = hospitalService.findByHosName(hosname);
        return Result.ok(hospitalList);
    }

    /**
     * 根据医院编号获取科室
     *
     * @param hoscode
     * @return
     */
    @ApiOperation("根据医院编号获取科室")
    @GetMapping("department/{hoscode}")
    public Result findDepartment(@PathVariable String hoscode) {
        List<DepartmentVo> departmentVoList = departmentService.findDeptTree(hoscode);
        return Result.ok(departmentVoList);
    }

    /**
     * 根据医院编号获取医院预约详情
     *
     * @param hoscode
     * @return
     */
    @ApiOperation("根据医院编号获取医院预约详情")
    @GetMapping("findHospDetail/{hoscode}")
    public Result findHospDetail(@PathVariable String hoscode) {
        Map<String, Object> map = hospitalService.findHospDetail(hoscode);
        return Result.ok(map);
    }

    /**
     * 获取可以预约的排班数据
     *
     * @param page
     * @param limit
     * @param hoscode
     * @param depcode
     * @return
     */
    @ApiOperation("获取可以预约的排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     @PathVariable String hoscode,
                                     @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getBookingSchedule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    /**
     * 获取医院排班数据
     *
     * @param hoscode
     * @param depcode
     * @param workDate
     * @return
     */
    @ApiOperation("获取医院排班数据")
    @GetMapping("auth/findScheduleRule/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleRule(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    /**
     * 根据排班id来获取排班数据
     *
     * @param scheduleId
     * @return
     */
    @ApiOperation("根据排班id来获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getScheduleId(scheduleId);
        return Result.ok(schedule);
    }

    /**
     * 根据排班id获取到预约下单数据
     * @param scheduleId
     * @return
     */
    @ApiOperation("根据排班id获取到预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleQueryVo(@PathVariable String scheduleId) {
        ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVo(scheduleId);
        return scheduleOrderVo;
    }

    /**
     * 获取医院签名信息
     * @param hoscode
     * @return
     */
    @ApiOperation("获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable String hoscode){
        return hospitalSetService.getSignInfoVo(hoscode);
    }

}
